<%@ page pageEncoding="UTF-8"%>
<%@ include file="/common/token.jsp"%>
<%@ include file="/common/quest.jsp"%>
<%!
	String myAttention(Integer uid, Input input) {
		Integer page = 1; // 页码
		Integer itemCount = input.getInt("item_count", 20); // 每一页条目
		Integer category = input.getInt("category", -1); // 新闻类别
		Integer hospital = input.getInt("hospital", -1); // 医院id
		Integer branch = input.getInt("branch", -1); // 医院分支  不传返回所有
		Integer tag = input.getInt("tag", -1); // 新闻标记, 区分视频3/附件2/普通新闻1/视频附件都有4   不传返回所有
		String sinceID = input.getDesc("since_id","0"); // 下拉刷新
		String maxID = input.getDesc("max_id","0"); // 上拉加载
		String order = "desc"; // 排序
		String newsId = "";
		String selectContent = "new map(n.id as id , n.newsId as news_id, n.url as url, n.title as title, n.summary as summary, n.time as time, n.img as img, n.jsonString as json, n.tag as tag, n.category as category, n.branchName as branch_name,o.id as oid,n.author as author)";
		String table = "News n, OperateHistory  o";
		Where where = new Where("n.id=o.oid").and("o.uid=", uid);
		if (!sinceID.equals("0")) {
			where.and("o.id > " + sinceID);
			order = "asc";
		} else if (!maxID.equals("0")) {
			where.and("o.id < " + maxID);
		}
		if (branch != -1) {
			where.and("n.branch=", branch);
		}
		if (tag != -1) {
			where.and("n.tag=", tag);
		}
		if (category != -1) 
			where.and("n.category=", category);
		List<Map> newsList = QBuilder.db("basedb").select(selectContent).from(table).where(where.and("n.hospital=", hospital).and("n.status = ", STATUS_ENABLE).and("o.category=", NEWS_CATEGORY).and("o.operate=", ATTENTION).and("o.status=", STATUS_ENABLE)).order("o.id", order).page(itemCount, page).query().getResultObj();
		if (order.equals("asc")) { // 上拉加载时倒序
			Collections.reverse(newsList);
		}
		OperateHistory oh = new OperateHistory();
		oh.setHospital(hospital);
		oh.setCategory(NEWS_CATEGORY);
		love(query(newsList, oh), uid, oh);
		Message msg = new Message(0);
		if (isEmpty(newsList))
			msg.setErrcodeAndErrmsg(30041, "没有更多了");
		msg.put("data", newsList);
		return msg.toJson();
	}
%>
<%
	Tools.encryptPrint(out, myAttention(token.getUid(), input));
%>
